package com.ddwl.goods.dao;

import com.ddwl.common.dao.TkDao;
import com.ddwl.common.util.BeanConverUtils;
import com.ddwl.goods.dto.ItemReserveDto;
import com.ddwl.goods.dao.mapper.ReserveMapper;
import com.ddwl.goods.dao.model.Reserve;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
import java.util.Set;

/**
 * 类ReserveDao.java的实现描述：TODO
 *
 * @author zach
 * @Date :2020-06-11 15:57.
 */
@Repository
public class ReserveDao extends TkDao<ReserveMapper, Reserve> {

    /**
     * 查询活动的预售信息
     * @param activityId
     * @return
     */
//    public List<Reserve> queryReserveByActivityId(String activityId){
//        Reserve reserve = new Reserve();
//        reserve.setActivityId(activityId);
//        return baseMapper.select(reserve);
//    }

    /**
     * 查询商品的预购信息
     * @param itemIds
     * @return
     */
    public List<ItemReserveDto> queryReserveByItemIds(Set<String> itemIds){
        Example example =getExample();
        example.and().andIn("itemId",itemIds);
        List< Reserve> reserves =  baseMapper.selectByExample(example);
        return BeanConverUtils.convertBeanList(reserves,ItemReserveDto.class);
    }



    public Integer deleteByItemId(String itemId){
        Reserve reserve=new Reserve();
        reserve.setItemId(itemId);
        return baseMapper.delete(reserve);
    }

    public Reserve queryReserveByItemId(String itemId){
        return baseMapper.queryReserveByItemId(itemId);

    }
}
